Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch atomic.Value to atomic.Pointer for spanProcessorStates #3926

Merged
merged 3 commits into from
Mar 27, 2023
Merged

Switch atomic.Value to atomic.Pointer for spanProcessorStates #3926

merged 3 commits into from
Mar 27, 2023

Conversation

dmathieu
Copy link
Member

This is a first look at switching atomic.Value to atomic.Pointer, so we have better type safety, and supposedly better readability.
I'm saying "supposedly" for better readability because for this specific case, it requires doing a lot of going from pointer to value, as a slice type can't be used from its pointer.

See #3918.

@dmathieu dmathieu added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Mar 23, 2023
@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Merging #3926 (dbd9e0b) into main (89e383f) will not change coverage.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #3926   +/-   ##
=====================================
  Coverage   81.8%   81.8%           
=====================================
  Files        170     170           
  Lines      12911   12911           
=====================================
  Hits       10563   10563           
  Misses      2129    2129           
  Partials     219     219           
Impacted Files Coverage Δ
sdk/trace/provider.go 87.2% <100.0%> (ø)
sdk/trace/span.go 87.9% <100.0%> (ø)
sdk/trace/tracer.go 100.0% <100.0%> (ø)

@pellared
Copy link
Member

Is there any performance difference?

@dmathieu
Copy link
Member Author

There is zero performance difference based on the existing benchmark tests.

pkg: go.opentelemetry.io/otel/sdk/trace
                                              │ bench-main  │            bench-branch            │
                                              │   sec/op    │   sec/op     vs base               │
SpanProcessor-10                                6.665µ ± 3%   6.501µ ± 2%  -2.47% (p=0.001 n=10)
SpanProcessorVerboseLogging-10                  6.543µ ± 2%   6.518µ ± 5%       ~ (p=0.684 n=10)
SpanLimits/AttributeValueLengthLimit-10         4.657µ ± 2%   4.621µ ± 2%       ~ (p=0.224 n=10)
SpanLimits/AttributeCountLimit-10               3.916µ ± 1%   3.873µ ± 1%  -1.10% (p=0.014 n=10)
SpanLimits/EventCountLimit-10                   4.228µ ± 1%   4.193µ ± 1%       ~ (p=0.143 n=10)
SpanLimits/LinkCountLimit-10                    4.218µ ± 2%   4.206µ ± 1%       ~ (p=0.897 n=10)
SpanLimits/AttributePerEventCountLimit-10       4.323µ ± 1%   4.326µ ± 1%       ~ (p=0.956 n=10)
SpanLimits/AttributePerLinkCountLimit-10        4.312µ ± 1%   4.303µ ± 1%       ~ (p=0.306 n=10)
SpanSetAttributesOverCapacity-10                1.430µ ± 1%   1.421µ ± 1%  -0.66% (p=0.000 n=10)
StartEndSpan/AlwaysSample-10                    389.7n ± 1%   384.8n ± 1%  -1.27% (p=0.000 n=10)
StartEndSpan/NeverSample-10                     175.2n ± 1%   172.4n ± 1%  -1.57% (p=0.000 n=10)
SpanWithAttributes_4/AlwaysSample-10            678.0n ± 1%   676.7n ± 1%       ~ (p=0.448 n=10)
SpanWithAttributes_4/NeverSample-10             257.2n ± 2%   255.9n ± 1%       ~ (p=0.160 n=10)
SpanWithAttributes_8/AlwaysSample-10            891.5n ± 2%   888.2n ± 1%       ~ (p=0.579 n=10)
SpanWithAttributes_8/NeverSample-10             318.9n ± 1%   320.3n ± 1%       ~ (p=0.403 n=10)
SpanWithAttributes_all/AlwaysSample-10          817.5n ± 1%   809.5n ± 3%       ~ (p=0.210 n=10)
SpanWithAttributes_all/NeverSample-10           275.6n ± 1%   275.8n ± 2%       ~ (p=0.956 n=10)
SpanWithAttributes_all_2x/AlwaysSample-10       1.135µ ± 1%   1.127µ ± 1%       ~ (p=0.270 n=10)
SpanWithAttributes_all_2x/NeverSample-10        359.5n ± 1%   359.8n ± 1%       ~ (p=0.699 n=10)
SpanWithEvents_4/AlwaysSample-10                876.8n ± 1%   857.5n ± 1%  -2.20% (p=0.001 n=10)
SpanWithEvents_4/NeverSample-10                 181.7n ± 1%   181.0n ± 1%       ~ (p=0.171 n=10)
SpanWithEvents_8/AlwaysSample-10                1.315µ ± 0%   1.311µ ± 1%       ~ (p=0.091 n=10)
SpanWithEvents_8/NeverSample-10                 188.4n ± 1%   187.2n ± 1%  -0.61% (p=0.005 n=10)
SpanWithEvents_WithStackTrace/AlwaysSample-10   557.1n ± 1%   546.9n ± 1%  -1.85% (p=0.000 n=10)
SpanWithEvents_WithStackTrace/NeverSample-10    198.5n ± 1%   197.4n ± 1%  -0.53% (p=0.024 n=10)
SpanWithEvents_WithTimestamp/AlwaysSample-10    540.5n ± 1%   532.2n ± 1%  -1.53% (p=0.000 n=10)
SpanWithEvents_WithTimestamp/NeverSample-10     230.8n ± 1%   228.9n ± 1%  -0.82% (p=0.001 n=10)
TraceID_DotString-10                            44.20n ± 0%   44.15n ± 0%       ~ (p=0.470 n=10)
SpanID_DotString-10                             34.76n ± 1%   34.61n ± 1%       ~ (p=0.055 n=10)
geomean                                         727.5n        722.4n       -0.71%

                                              │  bench-main  │             bench-branch              │
                                              │     B/op     │     B/op      vs base                 │
SpanProcessor-10                                8.266Ki ± 0%   8.266Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanProcessorVerboseLogging-10                  8.266Ki ± 0%   8.266Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributeValueLengthLimit-10         10.39Ki ± 0%   10.39Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributeCountLimit-10               8.375Ki ± 0%   8.375Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/EventCountLimit-10                   10.03Ki ± 0%   10.03Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/LinkCountLimit-10                    10.03Ki ± 0%   10.03Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributePerEventCountLimit-10       10.25Ki ± 0%   10.25Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributePerLinkCountLimit-10        10.25Ki ± 0%   10.25Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanSetAttributesOverCapacity-10                  496.0 ± 0%     496.0 ± 0%       ~ (p=1.000 n=10) ¹
StartEndSpan/AlwaysSample-10                      432.0 ± 0%     432.0 ± 0%       ~ (p=1.000 n=10) ¹
StartEndSpan/NeverSample-10                       128.0 ± 0%     128.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_4/AlwaysSample-10            1.109Ki ± 0%   1.109Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_4/NeverSample-10               384.0 ± 0%     384.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_8/AlwaysSample-10            1.859Ki ± 0%   1.859Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_8/NeverSample-10               640.0 ± 0%     640.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all/AlwaysSample-10          1.672Ki ± 0%   1.672Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all/NeverSample-10             448.0 ± 0%     448.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all_2x/AlwaysSample-10       2.984Ki ± 0%   2.984Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all_2x/NeverSample-10          768.0 ± 0%     768.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_4/AlwaysSample-10                  864.0 ± 0%     864.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_4/NeverSample-10                   128.0 ± 0%     128.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_8/AlwaysSample-10                1.281Ki ± 0%   1.281Ki ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_8/NeverSample-10                   128.0 ± 0%     128.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithStackTrace/AlwaysSample-10     544.0 ± 0%     544.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithStackTrace/NeverSample-10      144.0 ± 0%     144.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithTimestamp/AlwaysSample-10      568.0 ± 0%     568.0 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithTimestamp/NeverSample-10       168.0 ± 0%     168.0 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                         1.203Ki        1.203Ki       +0.00%
¹ all samples are equal

                                              │ bench-main │            bench-branch             │
                                              │ allocs/op  │ allocs/op   vs base                 │
SpanProcessor-10                                36.00 ± 0%   36.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanProcessorVerboseLogging-10                  36.00 ± 0%   36.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributeValueLengthLimit-10         63.00 ± 0%   63.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributeCountLimit-10               54.00 ± 0%   54.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/EventCountLimit-10                   55.00 ± 0%   55.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/LinkCountLimit-10                    55.00 ± 0%   55.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributePerEventCountLimit-10       58.00 ± 0%   58.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanLimits/AttributePerLinkCountLimit-10        58.00 ± 0%   58.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanSetAttributesOverCapacity-10                3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
StartEndSpan/AlwaysSample-10                    2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
StartEndSpan/NeverSample-10                     2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_4/AlwaysSample-10            6.000 ± 0%   6.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_4/NeverSample-10             3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_8/AlwaysSample-10            7.000 ± 0%   7.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_8/NeverSample-10             3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all/AlwaysSample-10          7.000 ± 0%   7.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all/NeverSample-10           3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all_2x/AlwaysSample-10       8.000 ± 0%   8.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithAttributes_all_2x/NeverSample-10        3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_4/AlwaysSample-10                9.000 ± 0%   9.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_4/NeverSample-10                 2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_8/AlwaysSample-10                14.00 ± 0%   14.00 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_8/NeverSample-10                 2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithStackTrace/AlwaysSample-10   5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithStackTrace/NeverSample-10    3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithTimestamp/AlwaysSample-10    6.000 ± 0%   6.000 ± 0%       ~ (p=1.000 n=10) ¹
SpanWithEvents_WithTimestamp/NeverSample-10     4.000 ± 0%   4.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                         8.628        8.628       +0.00%
¹ all samples are equal

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK with the PR, but TBH I am not sure if it is worth addressing globally.

Personally, I see almost no value. Someone needs to write the code, then others need to review and a maintainer needs to merge 😉

However, for sure it would be OK to use atomic.Pointer in "new codebase" or during refactoring. Finally, it is very good to know that there are no performance differences.

@dmathieu
Copy link
Member Author

I agree, there is null value in doing this everywhere. I did it in the tracer as a quick one to start looking at the related issue. But I don't think we should apply the principle in other places.

@MrAlias MrAlias merged commit ae90c44 into open-telemetry:main Mar 27, 2023
@dmathieu dmathieu deleted the span-processor-states-pointer branch March 27, 2023 16:41
@XSAM XSAM added this to the Old Untracked PRs milestone Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants